package org.concept.box.util;

import java.util.ArrayList;
import java.util.List;

public class StringUtils {

	public static String[] split(String str, char split) {
		List<String> result = new ArrayList<String>();
		if (str != null && str.length() > 0) {
			int start = 0;
			int pos = 0;
			while ((pos = str.indexOf(split, start)) >= 0) {
				if (pos > start) {
					result.add(str.substring(start, pos));
				}
				start = pos + 1;
			}
			if (start < str.length()) {
				result.add(str.substring(start));
			}
		}
		return result.toArray(new String[result.size()]);
	}

	public static void main(String[] args) {
		String str = "11111111111111111111a";
		for (int i = 0; i < 3; i++) {
			str += str;
		}
		System.out.println(str.length());
		final char splitc = 'a';
		long start = System.nanoTime();
		for (int i = 0; i < 10000; i++) {
			split(str, splitc);
		}
		long end = System.nanoTime();
		long t = end - start;
		System.out.println(t);
		String split = String.valueOf(splitc);
		start = System.nanoTime();
		for (int i = 0; i < 10000; i++) {
			str.split(split);
		}
		end = System.nanoTime();
		long t2 = end - start;
		System.out.println(t2);
		System.out.println(((int) (1.0 * t2 / t * 100)) / 100.0);
	}
}
